package com.guomao.demob;

import java.lang.reflect.Field;

public class JavaDemo5 {

    public static void main(String[] args) throws Exception {

        Class<?> clazz = Class.forName("com.guomao.demoa.Person");

//        clazz.getDeclaredConstructor()
//        clazz.getDeclaredMethod()

//        Field[] fields = clazz.getFields();

//        Field[] fields = clazz.getDeclaredFields();
//        System.out.println(fields.length);
//
//        for (Field f : fields) {
//            System.out.println(f);
//        }

        Object o = clazz.newInstance();
        System.out.println(o);

        Field field = clazz.getDeclaredField("age");
//        System.out.println(field);
        field.setAccessible(true);
        field.set(o, 18);

        Field field1 = clazz.getDeclaredField("name");
        field1.setAccessible(true);
        field1.set(o, "jack");

        System.out.println(o);
    }
}
